//
//  NYExamineTestTimeFooterView.m
//  NiuWaJiaoYu
//
//  Created by 袁航 on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYExamineTestTimeFooterView.h"
@interface NYExamineTestTimeFooterView ()
@property(nonatomic, strong) TTTAttributedLabel *textLabel;


@end
@implementation NYExamineTestTimeFooterView


- (void)setTestListModel:(NYExamineTestListModel *)testListModel
{
        _testListModel = testListModel;
        [self updateContent];
}
- (void)updateContent
{
        int ex_num = (int)(self.testListModel.ex_num.intValue > 0 ?:self.testListModel.ex_list.count);
        int ex_usedtime = (int)(self.testListModel.ex_usedtime.intValue > 0 ?:90);
        NSString *textString = [NSString stringWithFormat:@"共有%d道题目，考试时间为%d分钟，共计100分",ex_num,ex_usedtime];
        [self.textLabel setText:textString afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
                NSRegularExpression *regular = [NSRegularExpression regularExpressionWithPattern:@"\\d+" options:(0) error:nil];
                [[regular matchesInString:mutableAttributedString.string options:(0) range:NSMakeRange(0, mutableAttributedString.string.length)] enumerateObjectsUsingBlock:^(NSTextCheckingResult * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        if (idx > 1) {
                                [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)(UIColorHex(0xFA8D00).CGColor) range:obj.range];
                        }
                }];
                return mutableAttributedString;
        }];
}
- (void)setupView
{
        [super setupView];
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.textLabel];
        [self addSubview:self.msgBtn];
        [self addSubview:self.submitBtn];
        self.msgBtn.qmui_borderPosition = QMUIBorderViewPositionLeft | QMUIBorderViewPositionRight;
        self.qmui_borderPosition = QMUIBorderViewPositionTop;
        [self.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.left.bottom.equalTo(self);
        }];
        
}

- (void)setStatus:(NYExamineRequestStatus)status {
        _status = status;
        if (_status == NYExamineRequestStatusCup) {
                
                [self.submitBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                        make.top.bottom.right.equalTo(self);
                        make.left.equalTo(self.textLabel.mas_right);
                        make.width.mas_equalTo(__WGWidth(125));
                }];
                
        } else {
                
                [self.msgBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                        make.top.bottom.equalTo(self);
                        make.left.equalTo(self.textLabel.mas_right);
                        make.width.mas_equalTo(__WGWidth(70));
                }];
                [self.submitBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                        make.top.bottom.right.equalTo(self);
                        make.left.equalTo(self.msgBtn.mas_right);
                        make.width.mas_equalTo(__WGWidth(125));
                }];
                
        }
}

- (TTTAttributedLabel *)textLabel
{
        if ( _textLabel == nil )
        {
                _textLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _textLabel.numberOfLines = 2;
                _textLabel.textColor = UIColorHex(0x666666);
                _textLabel.font = WGSystem12Font;
                _textLabel.textInsets = UIEdgeInsetsMake(15, 15, 15, 15);
        }
        return _textLabel;
}

- (QMUIButton *)msgBtn
{
        if ( _msgBtn == nil )
        {
                _msgBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImage liu_yan] title:@"留言"];
                _msgBtn.imagePosition = QMUIButtonImagePositionTop;
                _msgBtn.titleLabel.font = WGSystem13Font;
                _msgBtn.spacingBetweenImageAndTitle = __WGHeight(7);
                [_msgBtn setTitleColor:UIColorHex(0x666666) forState:(UIControlStateNormal)];
        }
        return _msgBtn;
}
- (QMUIButton *)submitBtn
{
        if ( _submitBtn == nil )
        {
                _submitBtn = [[QMUIButton alloc] qmui_initWithImage:nil title:@"立即交卷"];
                [_submitBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
                _submitBtn.titleLabel.font = WGSystem16Font;
                _submitBtn.backgroundColor = UIColorHex(0xfa8d00);
        }
        return _submitBtn;
}
@end
